﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business.Entities;
using Negocio;

namespace UI.Desktop
{
    public partial class Modulos : Form
    {
        public Modulos()
        {
            InitializeComponent();
            this.dgvModulos.AutoGenerateColumns = false;
            this.generarColumnas();
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            Close();
        }

        public void Listar()
        {
            ModuloLogic ml = new ModuloLogic();
            this.dgvModulos.DataSource = ml.getAll();

        }

        

        private void generarColumnas()
        {
            DataGridViewTextBoxColumn colId = new DataGridViewTextBoxColumn();
            colId.Name = "id";
            colId.HeaderText = "Id";
            colId.DataPropertyName = "id";
            colId.DisplayIndex = 0;
            this.dgvModulos.Columns.Add(colId);

            DataGridViewTextBoxColumn colDescripcion = new DataGridViewTextBoxColumn();
            colDescripcion.Name = "descripcion";
            colDescripcion.HeaderText = "Descripcion";
            colDescripcion.DataPropertyName = "descripcion";
            colDescripcion.DisplayIndex = 1;
            this.dgvModulos.Columns.Add(colDescripcion);
        }

       
        
        

        

        

        private void tsNuevo_Click(object sender, EventArgs e)
        {
            ModuloDesktop md = new ModuloDesktop(ApplicationForm.modoForm.Alta);
            md.ShowDialog();
            this.Listar();
        }

        private void tsEditar_Click(object sender, EventArgs e)
        {
            if (this.dgvModulos.SelectedRows.Count != 0)
            {
                int ID = ((Business.Entities.Modulo)this.dgvModulos.SelectedRows[0].DataBoundItem).ID;
                ModuloDesktop md = new ModuloDesktop(ID, ApplicationForm.modoForm.Modificacion);
                md.ShowDialog();
            }
        }

        private void tsBorrar_Click(object sender, EventArgs e)
        {
            if (this.dgvModulos.SelectedRows.Count != 0)
            {
                int ID = ((Business.Entities.Modulo)this.dgvModulos.SelectedRows[0].DataBoundItem).ID;
                ModuloDesktop md = new ModuloDesktop(ID, ApplicationForm.modoForm.Baja);
                md.ShowDialog();
            }
        }

        private void btnActualizar_Click(object sender, EventArgs e)
        {
            this.Listar();
        }

        private void toolStripContainer1_TopToolStripPanel_Click(object sender, EventArgs e)
        {

        }

        private void Modulos_Load(object sender, EventArgs e)
        {
            this.Listar();
        }

       

        

       

       
    }
}
